package org.studiox.graph.persistence.mybatis.tk.mapper;

import org.apache.ibatis.annotations.*;
import org.studiox.graph.persistence.mybatis.tk.base.BaseGraphMapper;
import org.studiox.graph.persistence.mybatis.tk.domain.GraphVertexDO;

import java.util.List;

public interface GraphVertexMapper extends BaseGraphMapper<GraphVertexDO> {

  @Select("select id from graph_vertex")
  List<Long> getGraphVertexIds();

  @Select("select uniq from graph_vertex")
  List<String> getGraphVertexUniqs();

  @Select("select id from graph_vertex where uniq=#{uniq}")
  Long getGraphVertexIdByUniq(@Param("uniq") String uniq);

  @Select("select janus_vertex_id from graph_vertex where uniq=#{uniq}")
  Long getJanusVertexIdByUniq(@Param("uniq") String uniq);

  @Select("select * from graph_vertex where uniq=#{uniq}")
  @Results(
      id = "graphVertexDoByUniqMap",
      value = {
        @Result(id = true, column = "id", property = "id"),
        @Result(column = "uniq", property = "uniq"),
        @Result(column = "type", property = "type"),
        @Result(column = "owner", property = "owner"),
        @Result(column = "janus_vertex_id", property = "janusVertexId"),
        @Result(column = "neo4j_vertex_id", property = "neo4jVertexId"),
        @Result(column = "nebula_vertex_id", property = "nebulaVertexId"),
        @Result(column = "temp", property = "temp"),
        @Result(column = "deleted", property = "deleted"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "update_time", property = "updateTime")
      })
  GraphVertexDO getGraphVertexDoByUniq(@Param("uniq") String uniq);

  @Select("select * from graph_vertex where uniq like #{uniqLikeStr}")
  @Results(
      id = "graphVertexDosByUniqLikeMap",
      value = {
        @Result(id = true, column = "id", property = "id"),
        @Result(column = "uniq", property = "uniq"),
        @Result(column = "type", property = "type"),
        @Result(column = "owner", property = "owner"),
        @Result(column = "janus_vertex_id", property = "janusVertexId"),
        @Result(column = "neo4j_vertex_id", property = "neo4jVertexId"),
        @Result(column = "nebula_vertex_id", property = "nebulaVertexId"),
        @Result(column = "temp", property = "temp"),
        @Result(column = "deleted", property = "deleted"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "update_time", property = "updateTime")
      })
  List<GraphVertexDO> getGraphVertexDosByUniqLike(@Param("uniqLikeStr") String uniqLikeStr);

  @Update("update graph_vertex set janus_vertex_id=#{janusVertexId} where id=#{id}")
  void updateJanusVertexId(@Param("id") Long id, @Param("janusVertexId") Long janusVertexId);

  @Update("update graph_vertex set neo4j_vertex_id=#{neo4jVertexId} where id=#{id}")
  void updateNeo4jVertexId(@Param("id") Long id, @Param("neo4jVertexId") Long neo4jVertexId);

  @Update("update graph_vertex set nebula_vertex_id=#{nebulaVertexId} where id=#{id}")
  void updateNebulaVertexId(@Param("id") Long id, @Param("nebulaVertexId") Long nebulaVertexId);
}
